package com.jd.basic.dto;

import com.jd.basic.utils.MD5Utils;
import com.jd.basic.utils.StrUtils;
import com.jd.user.domain.Logininfo;
import com.jd.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import sun.security.util.Password;

import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @author 小林同学
 * @version 1.0
 * @description: TODO
 * @date 2023/3/5 20:19
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RegisterDto {
    @NotBlank(message = "电话号码不能为空")
    private String phone;

    private String imageCodeKey;
    @NotBlank(message = "图形不能为空")
    private String imageCodeValue;
    @NotBlank(message = "短信验证码不能为空")
    private String smsCode;
    @NotBlank(message = "密码不能为空")
    private String password;
    @NotBlank(message = "确认密码不能为空")
    private String passwordConfirm;

    private String type;

    public User getUser(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        /// 加密密码
        String pw = MD5Utils.encrypByMd5(salt + this.password);
        return User.builder()
                .phone(this.phone)
                .password(pw)
                .createtime(new Date())
                .salt(salt)
                .username(this.phone)
                .state(1)
                .build();
    }

    public Logininfo getLogininfo(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        /// 加密密码
        String pw = MD5Utils.encrypByMd5(salt + this.password);
        return Logininfo.builder()
                        .phone(this.phone)
                        .username(this.phone)
                        .salt(salt)
                        .type(1)
                        .password(pw)
                        .disable(true)
                        .build();

    }
}
